namespace BM.Tools.WebControls.MForm.Navigation.Predicates
{
    using BM.Tools.WebControls.MForm.Navigation.XPath.Predicates;

    /// <summary>
    /// A navigator for the <see cref="PositionPredicate" /> predicate locator.
    /// </summary>
    /// <typeparam name="T">
    /// The type of the navigable object.
    /// </typeparam>
    public class PositionPredicateNavigator<T> : PredicateNavigator<T, PositionPredicate>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PositionPredicateNavigator{T}"/> class. 
        /// </summary>
        /// <param name="parent">
        /// The parent.
        /// </param>
        /// <param name="locator">
        /// The locator.
        /// </param>
        public PositionPredicateNavigator(INavigator<T> parent, PositionPredicate locator) : base(parent, locator)
        {
        }

        /// <summary>
        /// Tests the navigable object position against the predicate position.
        /// </summary>
        /// <param name="navigable">
        /// The navigable.
        /// </param>
        /// <returns>
        /// Returns true is navigable position matches the predicate position, otherwise returns false.
        /// </returns>
        public override bool Matches(T navigable)
        {
            return Query(navigable).IndexEquals(Locator.Position);
        }
    }
}